import React from 'react'
import { registerMicroApps, start, initGlobalState, MicroAppStateActions } from 'qiankun';

const state = {
    name: 'qiankun框架'
}

// 初始化 state
const actions: MicroAppStateActions = initGlobalState(state)
actions.onGlobalStateChange((state, prev) => {
    console.log(state, prev)
})
setTimeout(() => {
    actions.setGlobalState({ ...state, web_name: 'qiankun框架888' })
}, 2000)
actions.offGlobalStateChange()

// 主要应用注册子应用
registerMicroApps([
    {
        name: 'game-brain', // app name registered
        entry: '//localhost:3002',
        container: '#game-brain',
        activeRule: '/game-brain',
        props: {
            web_name: 'React项目'
        }
    },
]);

start();

const Index = () => {
    return <div id="game-brain"></div>
}

export default Index
